<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <!-- <el-button @click="closeDrawer(2)" type="primary">保 存</el-button> -->
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">保 存</multiuse-button>
    </div>
  </div>
</template>
<script>
import {emitSave} from '@/api/omSale/vehicleParameters/vehicleColour/index.js';
import { dictionary } from '@/utils/dictMixin';
export default {
  data(){
    this.saveData=null;
    return{
      formList:this.createdFrom()
    }
  },
  props:['rowData'],
  created(){
    this.init()
  },
  mixins:[dictionary],
  methods:{
    createdFrom(){
      return [
        {
          type: 'SELECT',
          label: '颜色类型',
          fieldName: 'colorType',
          placeholder: '请选择',
          itemList:this.createDictList('1608'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '颜色代码',
          fieldName: 'colorCode',
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],

        },
        {
          type: 'INPUT',
          label: '颜色名称',
          fieldName: 'colorName',
          placeholder: '请输入',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],

        },
        {
          type: 'SELECT',
          label: '启用标记',
          fieldName: 'isValid',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }],

        },

      ]
    },
    changeHandle(val) {
      this.saveData = val;
    },
    init(){
      for(let i in this.rowData){
        this.formList.map(x=>{
          if(x.fieldName==i){
            x.initialValue=this.rowData[i];
          }
        })
      }
    },
    async closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }else{
        this.$refs.from.SUBMIT_FORM();
        console.log(this.saveData, 'this.saveData');
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          json.colorId=this.rowData.colorId
          json.recordVersion=this.rowData.recordVersion;
          let res = await emitSave(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success'
            });
            this.$emit('close', json);
          }else{
            this.saveData=null;
          }
        }

      }
    }
  }
}
</script>
